package vmcs.simulationsystem;

/**
 * Title:        VMCS
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      ISS
 * @author Pang Pingli
 * @version 1.0
 */
import java.awt.*;

import vmcs.common.VMCSException;
import vmcs.controller.MaintenanceController;
import vmcs.store.Store;
import vmcs.store.StoreController;
import vmcs.store.StoreItem;

public class CoinDisplay extends Panel {

  public final static String     TITLE = "Quantity of Coins Available";

  private StoreController         storeCtrl;
  private MaintenanceController      mCtrl;
  private ButtonItemDisplay       bi;
  private int                     len;
  private int                     curIdx;

  public CoinDisplay(MaintenanceController  mctrl) {
    mCtrl = mctrl;
    storeCtrl = mCtrl.getMainController().getStoreController();

     int   i;
    len = storeCtrl.getStoreSize(Store.CASH);
    StoreItem[]  items = storeCtrl.getStoreItems(Store.CASH);

    bi = new ButtonItemDisplay(TITLE, items, len);

    bi.addListener(new CoinDisplayListener(mCtrl));

    bi.clear();

    this.add(bi);

  }

  public void setActive(boolean st){
    bi.setActive(st);
  }

  /**
   * Display the quantity of selected coin, clear other display.
   */
  public void displayQty(int idx, int qty)
  throws VMCSException {
    curIdx = idx;
    bi.clear();
    bi.displayQty(idx, qty);
  }


  /**
   * get the current displayed coin index. This is used for updating when store MachinerySimulatorPanel is changed.
   * Not required.
   */
  public int getCurIdx(){
    return curIdx;
  }
}